package ruifight.member.service.base;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import ruifight.member.dao.base.BaseMapper;
@Service
public class BaseServiceImpl<T1, T2, PK extends Serializable> implements BaseService<T1, T2, PK>{
	@Autowired
	private BaseMapper<T1,T2, PK> baseMapper;

	@Override
	public int deleteByPrimaryKey(PK p) {
		// TODO Auto-generated method stub
		return baseMapper.deleteByPrimaryKey(p);
	}
	
	@Override
	public int deleteByExample(T2 example) {
		// TODO Auto-generated method stub
		return baseMapper.deleteByExample(example);
	}
	
	@Override
	public int insert(T1 t) {
		// TODO Auto-generated method stub
		return baseMapper.insert(t);
	}

	@Override
	public int insertSelective(T1 t) {
		// TODO Auto-generated method stub
		return baseMapper.insertSelective(t);
	}

	@Override
	public T1 selectByPrimaryKey(PK p) {
		// TODO Auto-generated method stub
		return baseMapper.selectByPrimaryKey(p);
	}

	@Override
	public int updateByPrimaryKeySelective(T1 t) {
		// TODO Auto-generated method stub
		return baseMapper.updateByPrimaryKeySelective(t);
	}

	@Override
	public int updateByPrimaryKey(T1 t) {
		// TODO Auto-generated method stub
		return baseMapper.updateByPrimaryKey(t);
	}

	@Override
	public int updateByExampleSelective(T1 t, T2 example) {
		// TODO Auto-generated method stub
		return baseMapper.updateByExampleSelective(t, example);
	}

	@Override
	public int updateByExample(T1 t, T2 example) {
		// TODO Auto-generated method stub
		return baseMapper.updateByExample(t, example);
	}
	
	@Override
	public int countByExample(T2 example) {
		// TODO Auto-generated method stub
		return baseMapper.countByExample(example);
	}

	@Override
	public List<T1> selectByExample(T2 example) {
		// TODO Auto-generated method stub
		return baseMapper.selectByExample(example);
	}
	@Override
	public T1 selectOneByExample(T2 example) {
		PageHelper.startPage(1, 1);
		List<T1> dataList = baseMapper.selectByExample(example);
		if(dataList!=null&&dataList.size()>0) {
			return dataList.get(0);
		}
		return null;
	}
	@Override
	public PageInfo<T1> getPage(int pageNum, int pageSize, T2 example) {
		PageHelper.startPage(pageNum, pageSize);
        List<T1> pageList = baseMapper.selectByExample(example);
        PageInfo<T1> pageInfo = new PageInfo<T1>(pageList);
        return pageInfo;
	}
}
